package com.yf.system.aspect;

import com.yf.framework.aspect.log.LogDataSetter;
import com.yf.framework.aspect.log.LogProducer;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * 日志过滤
 *
 * @author bool
 */
@Order(2)
@Aspect
@Component
public class LogAspect {


    @Autowired
    private LogDataSetter logDataSetter;


    @Autowired
    private HttpServletRequest request;


    /**
     * 针对注解过的方法，进行保存日志
     *
     * @param jp
     * @return
     * @throws Throwable
     */
    @Around("@annotation(com.yf.framework.annotation.LogInject)")
    public Object doAround(ProceedingJoinPoint jp) throws Throwable {
        return new LogProducer(request, logDataSetter).record(jp);
    }


}
